package 博客;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

public class Test {
    public static void main(String[] args) {

        String[] str = {"兽宝一号","兽宝二号","兽宝三号"};
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list,str);

        Collections.shuffle(list);
        System.out.println(list);
        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String s1, String s2) {
                if(s1.charAt(2) == '一'){
                    return -1;
                }
                if(s1.charAt(2) == '二' && s2.charAt(2) != '一'){
                    return -1;
                }
                else{
                    return 1;
                }
            }
        });
        System.out.println(list);

    }
}


/*

* 可变参数本质上就是一个数组
* 作用: 接受多个参数
* 格式: 数据类型...参数名称

public void methodName(Type... parameterName) {
    // 方法体
}

public static int sum(int... numbers) {
    int result = 0;
    for (int number : numbers) {
        result += number;
    }
    return result;
}

int result1 = sum(1, 2, 3, 4, 5); // result1 = 15
int result2 = sum(10, 20, 30);    // result2 = 60
int result3 = sum();              // result3 = 0


* */



